package cn.edu.hust.sse.software7.class3.serviceImpl;

import java.util.List;
import java.util.logging.Logger;

import cn.edu.hust.sse.software7.class3.DAO.EBAdminDAO;
import cn.edu.hust.sse.software7.class3.entities.EBAdmin;
import cn.edu.hust.sse.software7.class3.service.EBAdminService;

public class EBAdminServiceImpl implements EBAdminService {
	private static Logger log;
	EBAdminDAO dao = new EBAdminDAO();

	public EBAdminServiceImpl() {
		if (dao == null) {
			dao = new EBAdminDAO();
		}
		log = Logger.getLogger(EBAdminServiceImpl.class.getName());
	}
	
	@Override
	public boolean isInited() {
		return dao.isInited();
	}

	@Override
	public boolean isExistedAdmin(String adName) {
		return dao.isExistedAdmin(adName);
	}

	@Override
	public void addAdmin(EBAdmin admin) {
		boolean checkExist = dao.isExistedAdmin(admin.getAdName());
		if (!checkExist) {
			dao.addAdmin(admin);
		} else {
			log.info("administrator with the name of " + admin.getAdName()
					+ "is already exist.");
		}
	}

	@Override
	public void deleteAdmin(EBAdmin admin) {
		boolean checkExist = dao.isExistedAdmin(admin.getAdName());
		if (checkExist) {
			dao.deleteAdmin(admin);
		} else {
			log.info("administrator with the name of " + admin.getAdName()
					+ "is not exist as all.");
		}
	}

	@Override
	public void deleteAllAdmin(List<EBAdmin> admins) {
		if (!admins.isEmpty()) {
			dao.deleteAllAdmin(admins);
		}
	}

	@Override
	public void updateAdmin(EBAdmin admin) {
		dao.updateAdmin(admin);
	}

	@Override
	public boolean validateAdmin(EBAdmin admin) {
		return dao.validateAdmin(admin);
	}

	@Override
	public List<EBAdmin> getAdmins() {
		return dao.getAdmins();
	}

	@Override
	public void deleteAdminById(Long adminId) {
		dao.deleteAdminById(adminId);	
	}

	@Override
	public EBAdmin getAdminById(Long adminId) {
		return dao.getAdminsById(adminId);
	}

}
